﻿using Microsoft.Practices.Prism.Events;

namespace Acme.Prism.Infrastructure
{

    /// <summary>
    /// Thanks to Glenn Block for showing this pattern to me.
    /// This resolver allows an event to be passed to an object, without actually allowing the 
    /// event aggreator to leak into the object because this class wraps and hides the event aggregator.
    /// When passed into a constructor, it declares intent, that the class will be using this event,
    /// rather than just the entire event aggreator and any events it has.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class EventAggregatorResolver<T> : IEventAggregatorResolver<T> where T : EventBase, new()
    {
        readonly IEventAggregator _eventAggregator;

        public EventAggregatorResolver(IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;
        }

        public T Resolve()
        {
            return _eventAggregator.GetEvent<T>();
        }
    }
}
